﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups.hiredoctor {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.controls.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.popups.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class HireDoctorPopupMediator extends AbstractPopupMediator {

        public var userModel:UserModel;
        private var payButton:LabelButton;
        private var askButton:LabelButton;
        private var roomId:String;

        private static const DOCTOR_PRICE:int = 500;

        override public function onRegister():void{
            super.onRegister();
            addContextListener(EventConstants.CLOSE_POPUP_BY_TYPE, this.onClosePopup, InfoEvent);
            var _local1:UIComponent = RepriseUtils.addComponent(this.view, "content");
            RepriseUtils.addComponent(this.view, "bear");
            var _local2:UIComponent = RepriseUtils.addComponent(_local1, "itemContainer");
            addLabel("headline showcardGothicFont", "hire_doctor_button", null, this.view);
            var _local3:UIComponent = RepriseUtils.addComponent(this.view, "buttonContainer");
            if (this.userModel.coins >= DOCTOR_PRICE){
                this.payButton = createButton(_local3, "greenButton", "global_button_pay_coins", "myriadProFont", {amount:DOCTOR_PRICE});
                eventMap.mapListener(this.payButton, MouseEvent.CLICK, this.onPayClick);
            } else {
                this.payButton = createButton(_local3, "greyButton", "global_button_pay_coins", "myriadProFont", {amount:DOCTOR_PRICE});
                this.payButton.enabled = false;
            };
            addLabel("continiousText myriadProFont", "global_or", null, _local3);
            this.askButton = createButton(_local3, "blueButton", "global_button_ask_a_friend", "myriadProFont");
            eventMap.mapListener(this.askButton, MouseEvent.CLICK, this.onAskClick);
        }
        private function onAskClick(_arg1:MouseEvent):void{
            this.dispatchAskForGift();
            close();
        }
        private function dispatchAskForGift():void{
            var _local1:Object = {request_type:GameConstants.DOCTOR, is_gift:false, entity_id:null};
            dispatch(new InfoEvent(EventConstants.SEND_GIFT_REQUEST, null, _local1));
        }
        private function onPayClick(_arg1:MouseEvent):void{
            var _local2:String = this.view.data.roomId;
            dispatch(new InfoEvent(GameConstants.BUY_A_DOCTOR, _local2));
        }
        private function get view():HireDoctorPopupView{
            return ((viewComponent as HireDoctorPopupView));
        }
        private function onClosePopup(_arg1:InfoEvent):void{
            if (_arg1.id == ProtocolConstants.BUY_DOCTOR){
                close();
            };
        }

    }
}//package net.wooga.pets.views.popups.hiredoctor 
